//
//  FunTableViewController.m
//  MKUITestApp
//
//  Created by 苏尚进 on 2020/8/21.
//  Copyright © 2020 moon. All rights reserved.
//

#import "FunTableViewController.h"
#import "MKTFuncItemTVCell.h"

#import "TableViewController.h"
#import "CollectionViewController.h"
#import "PickerViewController.h"
#import "MenuTableViewController.h"
#import "TabViewController.h"
#import "TestGridPageCollectionViewController.h"
#import "MyMenuTableViewController.h"
#import "TestCollectionViewPageFlowLayout.h"
#import "TestFlowButtonViewController.h"
#import "TestReloadTableViewController.h"
#import "MKTChatViewController.h"
#import "TestThemeViewController.h"
#import "TestGridPage.h"
#import "TestPageControll.h"
#import "TestLayoutConstraintViewController.h"
#import "TestCollectionViewWaterFlowLayout.h"
#import "TestFlowLayoutConstraint.h"
#import "TestListView.h"
#import "TestElementsViewController.h"
#import "TestElementsTableViewController.h"
#import "TestItemFlowCollectionViewController.h"
#import "TestFunTabBarViewController.h"
#import "TestUITabBarController.h"
#import "TestAlertViewController.h"
#import "TestPopoverViewController.h"
#import "TestNavBarLayoutConstraint.h"
#import "TestShadowViewController.h"
#import "TestEqualDivisionLayoutConstraint.h"
#import "TestCircleGestureView.h"
#import "TestMarqueeViewController.h"
#import "TestListIndexViewController.h"
@interface FunTableViewController ()
@property(nonatomic,strong) MKUITableView *tableView;
@end

@implementation FunTableViewController
+ (MKTFuncItem *)funcItem{
    return [MKTFuncItem funcWithName:@"Fun" viewControllerClass:self];
}
- (id)init{
    if(self=[super init]){
        self.tabBarItem.title = [self.class funcItem].name;
        self.title = [self.class funcItem].name;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView = [[MKUITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    //
    [self __reloadData];
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(__onRefresh:)];
}
//- (void)__onRefresh:(id)sender{
//    [self __reloadData];
//}
- (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
//    CGRect fullBounds = self.view.bounds;
//    CGRect bounds = fullBounds;
//    if (@available(iOS 11.0, *)) {
//        bounds = self.view.safeAreaLayoutGuide.layoutFrame;
//    } else {
//    }
    if (@available(iOS 11.0, *)) {
        NSLog(@"FunTableViewController safeAreaInsets:%@",NSStringFromUIEdgeInsets(self.view.safeAreaInsets));
    }
    self.tableView.frame = self.view.bounds;
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self.tableView.model deselectAllCellModelsWithAnimated:YES];//取消选中
}
- (void)__reloadData{
    [self.tableView.model removeAllSectionModels];
    [self addCellModelWithItem:[TableViewController funcItem]];
    [self addCellModelWithItem:[CollectionViewController funcItem]];
    [self addCellModelWithItem:[PickerViewController funcItem]];
    [self addCellModelWithItem:[TabViewController funcItem]];
    [self addCellModelWithItem:[TestItemFlowCollectionViewController funcItem]];
    
    [self addCellModelWithItem:[MenuTableViewController funcItem]];
    [self addCellModelWithItem:[TestGridPageCollectionViewController funcItem]];
    [self addCellModelWithItem:[MyMenuTableViewController funcItem]];
    [self addCellModelWithItem:[TestCollectionViewPageFlowLayout funcItem]];
    [self addCellModelWithItem:[TestGridPage funcItem]];
    
    [self addCellModelWithItem:[TestListView funcItem]];
    [self addCellModelWithItem:[TestListIndexViewController funcItem]];
    
    [self addCellModelWithItem:[TestElementsViewController funcItem]];
    [self addCellModelWithItem:[TestElementsTableViewController funcItem]];
    [self addCellModelWithItem:[TestElementsTableViewController2 funcItem]];
    
    [self addCellModelWithItem:[TestFlowButtonViewController funcItem]];
    [self addCellModelWithItem:[TestReloadTableViewController funcItem]];
    [self addCellModelWithItem:[MKTChatViewController funcItem]];
    [self addCellModelWithItem:[TestThemeViewController funcItem]];
    [self addCellModelWithItem:[TestPageControll funcItem]];
    [self addCellModelWithItem:[TestLayoutConstraintViewController funcItem]];
    [self addCellModelWithItem:[TestCollectionViewWaterFlowLayout funcItem]];
    [self addCellModelWithItem:[TestFlowLayoutConstraint funcItem]];
    [self addCellModelWithItem:[TestFunTabBarViewController funcItem]];
    [self addCellModelWithItem:[TestUITabBarController funcItem]];
    
    [self addCellModelWithItem:TestAlertViewController.funcItem];
    [self addCellModelWithItem:TestPopoverViewController.funcItem];
    
    [self addCellModelWithItem:TestNavBarLayoutConstraint.funcItem];
    [self addCellModelWithItem:TestShadowViewController.funcItem];
    [self addCellModelWithItem:TestEqualDivisionLayoutConstraint.funcItem];
    [self addCellModelWithItem:TestCircleGestureView.funcItem];
    [self addCellModelWithItem:TestMarqueeViewController.funcItem];
    
    [self.tableView.model reloadTableViewData];
}
- (void)addCellModelWithItem:(MKTFuncItem *)item{
    @MK_WEAKIFY(self);
    MKUITableViewCellModel *cm = [MKUITableViewCellModel modelWithValue:item cellClass:[MKTFuncItemTVCell class] whenClick:^(__kindof MKUITableViewCellModel * _Nonnull cellModel) {
        @MK_NORMALIZEANDNOTNIL(self);
        UIViewController *v = [item createViewController];
        if(v){
            [cellModel.tableView.mk_navigationControllerOfFirst pushViewController:v animated:YES];
        }
    }];
    [self.tableView.model addCellModel:cm];
}
@end
